puts "INFO: Running script [info script] @ [exec date]\n"

dbDeleteText -all

#create text for signal terminals
#foreach term [dbGet top.terms] {
#		set term_name [join [dbGet $term.name]]
#		set layer [dbGet $term.layer.name]
#		set bbox [dbGet $term.pinShapes.rect]
#		set x0 [lindex [join $bbox] 0]
#		set y0 [lindex [join $bbox] 1]
#
#		Puts "INFO: create text for port: $term_name"
#		add_text -height 0.01 -label $term_name -layer $layer -pt $x0 $y0
#}

foreach term [dbget top.insts.instTerms.name *PAD] {
		set inst [dbget [dbget -p2 top.insts.instTerms.name $term].name]
		set net [dbget [dbget -p top.insts.instTerms.name $term].net.name]
		set rect [dbget [dbget -p2 [dbget -p top.insts.instTerms.name $term].cellTerm.pins.layerShapeShapes.layer.name ME6].shapes.rect]
		set bbox [dbTransform -inst $inst -localPt $rect]
		set llx [lindex $bbox 0 0]
		set lly [lindex $bbox 0 1]
		set urx [lindex $bbox 0 2]
		set ury [lindex $bbox 0 3]
		set x [expr [expr $llx+$urx]/2]
		set y [expr [expr $lly+$ury]/2]
		Puts "INFO: create text for port: $term"
		add_text -height 1 -label $net -layer ME6 -pt $x $y
}



foreach inst [dbget [dbget -p2 top.insts.cell.name IVDDIO].name] {
		set net VDDIO
		set rect [dbget [dbget -p2 [dbget -p top.insts.name $inst].pgInstTerms.term.pins.layerShapeShapes.layer.name ME6].shapes.rect]
		set bbox [dbTransform -inst $inst -localPt $rect]
		foreach box $bbox {
				set llx [lindex $box 0]
				set lly [lindex $box 1]
				set urx [lindex $box 2]
				set ury [lindex $box 3]
				set x [expr [expr $llx+$urx]/2]
				set y [expr [expr $lly+$ury]/2]
				Puts "INFO: create text for port: $inst"
				createPGPin $net -geom ME6 $llx $lly $urx $ury
				add_text -height 0.5 -label $net -layer ME6 -pt $x $y
		}
}

foreach inst [dbget [dbget -p2 top.insts.cell.name IVSSIO].name] {
		set net VSSIO
		set rect [dbget [dbget -p2 [dbget -p top.insts.name $inst].pgInstTerms.term.pins.layerShapeShapes.layer.name ME6].shapes.rect]
		set bbox [dbTransform -inst $inst -localPt $rect]
		foreach box $bbox {
				set llx [lindex $box 0]
				set lly [lindex $box 1]
				set urx [lindex $box 2]
				set ury [lindex $box 3]
				set x [expr [expr $llx+$urx]/2]
				set y [expr [expr $lly+$ury]/2]
				Puts "INFO: create text for port: $inst"
				createPGPin $net -geom ME6 $llx $lly $urx $ury
				add_text -height 0.5 -label $net -layer ME6 -pt $x $y
		}
}

foreach inst [dbget [dbget -p2 top.insts.cell.name IVDD].name] {
		set net VDD
		set rect [dbget [dbget -p2 [dbget -p top.insts.name $inst].pgInstTerms.term.pins.layerShapeShapes.layer.name ME6].shapes.rect]
		set bbox [dbTransform -inst $inst -localPt $rect]
		foreach box $bbox {
				set llx [lindex $box 0]
				set lly [lindex $box 1]
				set urx [lindex $box 2]
				set ury [lindex $box 3]
				set x [expr [expr $llx+$urx]/2]
				set y [expr [expr $lly+$ury]/2]
				Puts "INFO: create text for port: $inst"
				createPGPin $net -geom ME6 $llx $lly $urx $ury
				add_text -height 0.5 -label $net -layer ME6 -pt $x $y
		}
}

foreach inst [dbget [dbget -p2 top.insts.cell.name IVSS].name] {
		set net VSS
		set rect [dbget [dbget -p2 [dbget -p top.insts.name $inst].pgInstTerms.term.pins.layerShapeShapes.layer.name ME6].shapes.rect]
		set bbox [dbTransform -inst $inst -localPt $rect]
		foreach box $bbox {
				set llx [lindex $box 0]
				set lly [lindex $box 1]
				set urx [lindex $box 2]
				set ury [lindex $box 3]
				set x [expr [expr $llx+$urx]/2]
				set y [expr [expr $lly+$ury]/2]
				Puts "INFO: create text for port: $inst"
				createPGPin $net -geom ME6 $llx $lly $urx $ury
				add_text -height 0.5 -label $net -layer ME6 -pt $x $y
		}
}




puts "INFO: Completed script [info script]\n"


